
<div id="wrapMain">
	<div id="innerMain">
	<div class="row">
       <?php if($data['error']){
	echo "<div class='alert alert-danger'>";
	foreach($data[error] as $value)
	{
		echo "<div>".$value."</div>";
	}
	echo "</div>";   
   }else{ // START NO DATA ERROR ?>
  
  <?php //user_render_profile($data['user']); ?>
  <br/>
  <br/>
  <?php
  $base_url=HOME."user/".$_GET['u'];
  //if(strpos(url(),$base_url.'/video' !== fasle)){$next_url = $base_url . '/wall'};
  ?>
  
  

	 <div class="barinfo">
            <ul>
                <li><span><i class="icon-user"> </i><?php echo $_GET['u'] ?></span></li>
                <li><a href="<?php echo $base_url;?>/wall" <?php if(url()==$base_url || strpos(url(),$base_url.'/page')!==false ){ ?>class="active"<?php }?>>TẤT CẢ</a></li>
                <li><a href="<?php echo $base_url;?>/type/video" <?php if(strpos(url(),$base_url.'/video')!==false ){ ?>class="active"<?php }?>>VIDEO</a></li>
                    <li><a href="<?php echo $base_url;?>/type/picture" <?php if( strpos(url(),$base_url.'/picture')!==false ){ ?>class="active"<?php }?>>HÌNH ẢNH</a></li>
                      <li><a href="<?php echo $base_url;?>/type/text" <?php if( strpos(url(),$base_url.'/text')!==false ){ ?>class="active"<?php }?>>TRUYỆN</a></li>
               </li>
              
            </ul>
	</div>

   <Br/>
  <Br/>
  
	 <?php
     // RENDER GRID DATA USER POST --
	 if(isset($_GET['ext'])&& $_GET['ext']=='album'){
		  //Render album  ----
			 post_render_grid($data['info'],'','album');
		 	$page = isset($_GET['page']) ? $_GET['page'] : 1;
			$max_page = $data['page'];
			
		 //End of render album ----
	 }else{
		 //Render post
		$page = isset($_GET['page']) ? $_GET['page'] : 1;
		$max_page = $data['page'];
		post_render_grid($data['info'],'','',$page);
		
		
		//End of render post
	 }
	 ?>
     
        <nav id="page-nav">
			<a href="index.php?module=ajax&act=ajax&case=3&u=<?php echo $_GET['u'] ?>&t=load_more_items&page=<?= $page; ?><?php if(isset($_GET['ext'])){ echo "&ext=".$_GET['ext']; } ?>">
            </a>
		</nav>
		

        
        
        <div class="loading" id="mainLoading"><div id="loadMoreItems" class="normalLoadBtn"><img width="20" src="public/images/loading.gif" alt="loading" /> Loading </div>
        <div class="clr"></div>
        
        </div>
		<div id="next-page"></div>
 
            <?php }
			// NO DATA ERROR 
			?>
            
</div> <!-- End of row -->
 </div> <!-- Inner main -->
 </div> <!-- Wrap main -->

  
         <script>
  $(function(){
	
    var max_page = '<?= $max_page ?>';
    var $container = $('#contentIndex');
    
    $container.imagesLoaded(function(){
    	 
      $container.masonry({
        itemSelector: '.item',
        columnWidth: 4,
		isFitWidth: true
      });
    });
    var nextSelector = '#page-nav a';
    var origNextUrl = $(nextSelector).attr('href');

    var pageRegex = /(page=)([0-9]+)/;
    var page  = origNextUrl.match(pageRegex)[2];
    var mypage = page;

    
    var loadedTime = 0;
    //$container.masonry( 'on', 'removeComplete', function( msnryInstance, removedItems ) {$('#mainLoading').hide();} )
    $container.infinitescroll({
	    navSelector  : '#page-nav',    // selector for the paged navigation 
	    nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
	    itemSelector : '.item',     // selector for all items you'll retrieve
	        
	    path: function(pageNum) {
		    
	    	newPage = mypage + 1;
	    	previousPage = parseInt(<?= $page; ?>) - parseInt(<?= LOAD_TIME; ?>);
	    	
	    	if(previousPage == 0) previousPage = 1;
	    	
	    	if(previousPage < 0) previousPage = null;
		    $('#mainLoading').show();

		    if(parseInt(mypage) >= parseInt(max_page)){
				$('#mainLoading').hide();
				if(previousPage != null){
					$('#next-page').append('<div class="normalLoadBtn" id="previousPage"><a href="' + '<?php echo url_ajax(); ?>' + previousPage + '"><i class=" icon-long-arrow-left"></i> Bài cũ hơn</a></div>');
				}
				$('#next-page').append('<div class="normalLoadBtn" id="nextPage">Hết dữ liệu</div>');
				return;
			}

	        if(loadedTime >= 0 && ((mypage + 1) % <?= LOAD_TIME ?> == 0) && mypage >= 1 ){
		        $('#mainLoading').hide();
		        if(previousPage != null){
					$('#next-page').append('<div class="normalLoadBtn" id="previousPage"><a href="' + '<?php echo url_ajax(); ?>' + previousPage + '"><i class=" icon-long-arrow-left"></i> Bài cũ hơn</a></div>');
				}
		        
		        $('#next-page').append('<div class="normalLoadBtn" id="nextPage"><a href="' + '<?php echo url_ajax(); ?>' + newPage+ '">Xem tiếp <i class=" icon-long-arrow-right"></i></a></div>');
	        }
	       
	        mypage++;
	        loadedTime++;
	        
	        return origNextUrl.replace( pageRegex, ("$1" + (mypage)));
        }
    },
      
      
      
      // trigger Masonry as a callback
      function( newElements ) {
    	$.each(newElements, function(e, index){
			//$(index).find(');
			attrHref = $(index).find('.hoverUnderline').attr('href');
			$(index).find('.hoverUnderline').attr('href', attrHref + '&pagerel=' + mypage);
			//alert(attrHref);
				FB.XFBML.parse(document.getElementById('innerItem-' + id + '-' + type));
		});
        // hide new items while they are loading
        var $newElems = $( newElements ).css({ opacity: 0 });
        // ensure that images load before adding to masonry layout
        $newElems.imagesLoaded(function(){
          // show elems now they're ready
          $newElems.animate({ opacity: 1 });
          $('.video_play_icon').center();
          $container.masonry( 'appended', $newElems, true );
		
          $('#mainLoading').hide();
        });
      }
    );
    	// Auto resize

  });
</script>     